<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>发布新帖子 - 查聊</title>
  <!-- 引入Tailwind CSS -->
  <script src="https://cdn.tailwindcss.com"></script>
  <!-- 引入Font Awesome -->
  <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
  
  <!-- 自定义Tailwind配置 -->
  <script>
    tailwind.config = {
      theme: {
        extend: {
          colors: {
            primary: '#4F46E5', // 主色调：紫色
            secondary: '#10B981', // 辅助色：绿色
            accent: '#F59E0B', // 强调色：橙色
            light: '#F3F4F6', // 浅色背景
            dark: '#1F2937', // 深色文本
          },
          fontFamily: {
            sans: ['Inter', 'system-ui', 'sans-serif'],
          },
        },
      }
    }
  </script>
  
  <!-- 自定义工具类 -->
  <style type="text/tailwindcss">
    @layer utilities {
      .content-auto {
        content-visibility: auto;
      }
      .scrollbar-hide {
        -ms-overflow-style: none;
        scrollbar-width: none;
      }
      .scrollbar-hide::-webkit-scrollbar {
        display: none;
      }
    }
  </style>
  
  <style>
    /* 基础样式 */
    body {
      font-family: 'Inter', system-ui, -apple-system, sans-serif;
    }
    
    /* 平滑滚动 */
    html {
      scroll-behavior: smooth;
    }
    
    /* 编辑器样式 */
    .editor-toolbar {
      border-bottom: 1px solid #e5e7eb;
    }
    .editor-toolbar button {
      @apply p-2 text-gray-600 hover:bg-gray-100 rounded transition-colors;
    }
    .editor-toolbar button.active {
      @apply text-primary bg-primary/10;
    }
    .editor-content {
      min-height: 300px;
      outline: none;
    }
    .editor-content h1 {
      @apply text-2xl font-bold text-gray-900 my-4;
    }
    .editor-content h2 {
      @apply text-xl font-bold text-gray-900 my-3;
    }
    .editor-content p {
      @apply text-gray-700 my-2;
    }
    .editor-content img {
      @apply max-w-full h-auto rounded-lg my-3;
    }
    .editor-content ul, .editor-content ol {
      @apply pl-6 my-2;
    }
    .editor-content ul {
      @apply list-disc;
    }
    .editor-content ol {
      @apply list-decimal;
    }
    .editor-content blockquote {
      @apply border-l-4 border-primary pl-4 py-1 text-gray-600 italic my-3;
    }
    .editor-content pre {
      @apply bg-gray-100 p-3 rounded-lg overflow-x-auto font-mono text-sm my-3;
    }
  </style>
</head>
<body class="bg-gray-50 text-gray-800">
  <!-- PC端导航栏 -->
  <header class="hidden md:block fixed top-0 left-0 right-0 bg-white shadow-sm z-30">
    <div class="container mx-auto px-4 py-3 flex items-center justify-between">
      <!-- Logo -->
      <a href="index.html" class="flex items-center space-x-2">
        <span class="text-primary text-2xl"><i class="fa fa-comments-o"></i></span>
        <span class="text-xl font-bold text-primary">查聊</span>
      </a>
      
      <!-- 搜索框 -->
      <div class="relative flex-1 max-w-xl mx-8">
        <input type="text" placeholder="搜索帖子、话题或用户..." 
               class="w-full pl-10 pr-4 py-2 rounded-full bg-light border border-gray-200 focus:outline-none focus:ring-2 focus:ring-primary/30 focus:border-primary transition-all">
        <span class="absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400">
          <i class="fa fa-search"></i>
        </span>
      </div>
      
      <!-- 导航链接 -->
      <nav class="flex items-center space-x-6">
        <a href="index.html" class="text-gray-600 hover:text-primary transition-colors">首页</a>
        <a href="#" class="text-gray-600 hover:text-primary transition-colors">发现</a>
        <a href="new-post.html" class="px-4 py-2 bg-primary text-white rounded-full hover:bg-primary/90 transition-colors flex items-center space-x-1">
          <i class="fa fa-pencil"></i>
          <span>发帖</span>
        </a>
        <a href="profile.html" class="relative">
          <img src="https://picsum.photos/seed/user1/40/40" alt="用户头像" class="w-10 h-10 rounded-full object-cover border-2 border-white shadow-sm">
        </a>
      </nav>
    </div>
  </header>

  <!-- 移动端顶部导航 -->
  <header class="md:hidden fixed top-0 left-0 right-0 bg-white shadow-sm z-30">
    <div class="flex items-center justify-between p-4">
      <a href="index.html" class="text-gray-700">
        <i class="fa fa-arrow-left text-lg"></i>
      </a>
      <span class="font-medium text-gray-900">发布新帖子</span>
      <button id="publish-btn-mobile" class="text-primary font-medium">
        发布
      </button>
    </div>
  </header>

  <!-- 主要内容区域 -->
  <main class="container mx-auto px-4 pt-24 pb-20 md:pt-28">
    <div class="flex flex-col lg:flex-row gap-6">
      <!-- 左侧边栏 (PC端) -->
      <aside class="hidden lg:block w-64 shrink-0">
        <div class="bg-white rounded-xl shadow-sm p-5 sticky top-24">
          <!-- 用户信息 -->
          <div class="flex items-center space-x-3 mb-6">
            <img src="https://picsum.photos/seed/user1/60/60" alt="用户头像" class="w-12 h-12 rounded-full object-cover border-2 border-primary/20">
            <div>
              <h3 class="font-semibold text-gray-900">张三</h3>
              <p class="text-sm text-gray-500">@zhangsan</p>
            </div>
          </div>
          
          <!-- 导航菜单 -->
          <nav class="space-y-1">
            <a href="index.html" class="flex items-center space-x-3 p-3 rounded-lg text-gray-600 hover:bg-gray-50 transition-colors">
              <i class="fa fa-home w-5 text-center"></i>
              <span>首页</span>
            </a>
            <a href="#" class="flex items-center space-x-3 p-3 rounded-lg text-gray-600 hover:bg-gray-50 transition-colors">
              <i class="fa fa-compass w-5 text-center"></i>
              <span>发现</span>
            </a>
            <a href="favorites.html" class="flex items-center space-x-3 p-3 rounded-lg text-gray-600 hover:bg-gray-50 transition-colors">
              <i class="fa fa-star-o w-5 text-center"></i>
              <span>我的收藏</span>
              <span class="ml-auto bg-gray-100 text-gray-600 text-xs px-2 py-1 rounded-full">5</span>
            </a>
            <a href="#" class="flex items-center space-x-3 p-3 rounded-lg text-gray-600 hover:bg-gray-50 transition-colors">
              <i class="fa fa-bell-o w-5 text-center"></i>
              <span>通知</span>
              <span class="ml-auto bg-red-100 text-red-600 text-xs px-2 py-1 rounded-full">3</span>
            </a>
            <a href="profile.html" class="flex items-center space-x-3 p-3 rounded-lg text-gray-600 hover:bg-gray-50 transition-colors">
              <i class="fa fa-user-o w-5 text-center"></i>
              <span>个人中心</span>
            </a>
          </nav>
        </div>
      </aside>

      <!-- 中间内容区 -->
      <div class="flex-1">
        <!-- 发布帖子表单 -->
        <div class="bg-white rounded-xl shadow-sm overflow-hidden mb-6">
          <!-- 表单头部 -->
          <div class="p-5 border-b border-gray-100 flex items-center justify-between">
            <h2 class="font-bold text-xl text-gray-900">发布新帖子</h2>
            <div class="hidden md:flex items-center space-x-3">
              <button id="save-draft-btn" class="px-4 py-2 bg-gray-100 text-gray-700 rounded-lg hover:bg-gray-200 transition-colors">
                保存草稿
              </button>
              <button id="publish-btn" class="px-4 py-2 bg-primary text-white rounded-lg hover:bg-primary/90 transition-colors">
                发布帖子
              </button>
            </div>
          </div>
          
          <!-- 表单内容 -->
          <div class="p-5">
            <!-- 帖子标题 -->
            <div class="mb-6">
              <input type="text" placeholder="请输入帖子标题..." 
                     class="w-full px-4 py-3 text-lg border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary/30 focus:border-primary transition-all" maxlength="100">
              <p class="mt-1 text-xs text-gray-500 text-right">0/100</p>
            </div>
            
            <!-- 编辑器工具栏 -->
            <div class="editor-toolbar flex flex-wrap items-center gap-1 p-2 mb-2 bg-gray-50 rounded-t-lg">
              <button title="加粗" class=""><i class="fa fa-bold"></i></button>
              <button title="斜体" class=""><i class="fa fa-italic"></i></button>
              <button title="下划线" class=""><i class="fa fa-underline"></i></button>
              <span class="h-4 border-r border-gray-300 mx-1"></span>
              <button title="标题1" class=""><i class="fa fa-header"></i><sup>1</sup></button>
              <button title="标题2" class=""><i class="fa fa-header"></i><sup>2</sup></button>
              <span class="h-4 border-r border-gray-300 mx-1"></span>
              <button title="有序列表" class=""><i class="fa fa-list-ol"></i></button>
              <button title="无序列表" class=""><i class="fa fa-list-ul"></i></button>
              <button title="引用" class=""><i class="fa fa-quote-right"></i></button>
              <button title="代码块" class=""><i class="fa fa-code"></i></button>
              <span class="h-4 border-r border-gray-300 mx-1"></span>
              <button title="插入链接" class=""><i class="fa fa-link"></i></button>
              <label title="插入图片" class="cursor-pointer">
                <input type="file" accept="image/*" class="hidden">
                <i class="fa fa-image"></i>
              </label>
            </div>
            
            <!-- 内容编辑器 -->
            <div class="editor-content p-4 border border-gray-200 rounded-b-lg focus:ring-2 focus:ring-primary/30 focus:border-primary transition-all" contenteditable="true">
              <p>开始编写你的帖子内容...</p>
            </div>
            
            <!-- 图片上传区域 -->
            <div class="mt-4 grid grid-cols-3 gap-3" id="image-preview-container">
              <!-- 图片预览将在这里显示 -->
            </div>
            
            <!-- 分隔线 -->
            <div class="my-6 border-t border-gray-100"></div>
            
            <!-- 帖子分类 -->
            <div class="mb-6">
              <label class="block text-sm font-medium text-gray-700 mb-2">选择分类</label>
              <select class="w-full px-4 py-3 border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary/30 focus:border-primary transition-all">
                <option value="">请选择分类</option>
                <option value="tech">技术讨论</option>
                <option value="life">生活分享</option>
                <option value="question">问答求助</option>
                <option value="resource">资源分享</option>
                <option value="career">职场经验</option>
              </select>
            </div>
            
            <!-- 标签输入 -->
            <div class="mb-6">
              <label class="block text-sm font-medium text-gray-700 mb-2">添加标签（最多5个）</label>
              <div class="flex flex-wrap gap-2 mb-2" id="tag-container">
                <!-- 已添加的标签将在这里显示 -->
              </div>
              <div class="flex items-center space-x-2">
                <input type="text" placeholder="输入标签，按回车添加" id="tag-input" 
                       class="flex-1 px-4 py-2 border border-gray-200 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary/30 focus:border-primary transition-all">
                <button id="add-tag-btn" class="px-3 py-2 bg-primary text-white rounded-lg hover:bg-primary/90 transition-colors">
                  添加
                </button>
              </div>
              <p class="mt-1 text-xs text-gray-500">标签之间用空格分隔，最多添加5个标签</p>
            </div>
            
            <!-- 隐私设置 -->
            <div class="mb-6">
              <label class="flex items-center justify-between cursor-pointer">
                <span class="text-sm font-medium text-gray-700">仅自己可见</span>
                <div class="relative inline-block w-10 h-6">
                  <input type="checkbox" class="opacity-0 w-0 h-0">
                  <span class="absolute cursor-pointer inset-0 bg-gray-200 rounded-full transition-all before:absolute before:h-5 before:w-5 before:left-0.5 before:bottom-0.5 before:bg-white before:rounded-full before:transition-all"></span>
                </div>
              </label>
            </div>
          </div>
        </div>
      </div>

      <!-- 右侧边栏 (PC端) -->
      <aside class="hidden lg:block w-72 shrink-0">
        <!-- 发布指南 -->
        <div class="bg-white rounded-xl shadow-sm p-5 mb-6">
          <h3 class="font-semibold text-gray-900 mb-4 flex items-center">
            <i class="fa fa-lightbulb-o text-accent mr-2"></i>
            发布指南
          </h3>
          <ul class="space-y-2 text-sm text-gray-700">
            <li class="flex items-start space-x-2">
              <i class="fa fa-check-circle text-green-500 mt-1 shrink-0"></i>
              <span>标题应清晰明了，准确描述帖子内容</span>
            </li>
            <li class="flex items-start space-x-2">
              <i class="fa fa-check-circle text-green-500 mt-1 shrink-0"></i>
              <span>内容应详实有价值，避免发布无意义的信息</span>
            </li>
            <li class="flex items-start space-x-2">
              <i class="fa fa-check-circle text-green-500 mt-1 shrink-0"></i>
              <span>选择合适的分类，有助于更多人发现你的帖子</span>
            </li>
            <li class="flex items-start space-x-2">
              <i class="fa fa-check-circle text-green-500 mt-1 shrink-0"></i>
              <span>添加相关标签，提高帖子的曝光率</span>
            </li>
            <li class="flex items-start space-x-2">
              <i class="fa fa-exclamation-circle text-red-500 mt-1 shrink-0"></i>
              <span>请勿发布广告、垃圾信息或违反社区规范的内容</span>
            </li>
          </ul>
        </div>
        
        <!-- 热门标签 -->
        <div class="bg-white rounded-xl shadow-sm p-5 mb-6">
          <h3 class="font-semibold text-gray-900 mb-4">热门标签</h3>
          <div class="flex flex-wrap gap-2">
            <button class="px-3 py-1 bg-gray-100 text-gray-600 text-sm rounded-full hover:bg-gray-200 transition-colors">
              #前端开发
            </button>
            <button class="px-3 py-1 bg-gray-100 text-gray-600 text-sm rounded-full hover:bg-gray-200 transition-colors">
              #JavaScript
            </button>
            <button class="px-3 py-1 bg-gray-100 text-gray-600 text-sm rounded-full hover:bg-gray-200 transition-colors">
              #React
            </button>
            <button class="px-3 py-1 bg-gray-100 text-gray-600 text-sm rounded-full hover:bg-gray-200 transition-colors">
              #Vue
            </button>
            <button class="px-3 py-1 bg-gray-100 text-gray-600 text-sm rounded-full hover:bg-gray-200 transition-colors">
              #CSS
            </button>
            <button class="px-3 py-1 bg-gray-100 text-gray-600 text-sm rounded-full hover:bg-gray-200 transition-colors">
              #性能优化
            </button>
            <button class="px-3 py-1 bg-gray-100 text-gray-600 text-sm rounded-full hover:bg-gray-200 transition-colors">
              #UI设计
            </button>
          </div>
        </div>
        
        <!-- 广告横幅 -->
        <div class="bg-gradient-to-r from-primary to-purple-600 rounded-xl shadow-sm p-5 text-white">
          <h3 class="font-bold text-lg mb-2">加入查聊VIP</h3>
          <p class="text-sm text-white/80 mb-4">获取专属标识、无广告体验、优先客服等特权</p>
          <button class="w-full py-2 bg-white text-primary font-medium rounded-lg hover:bg-opacity-90 transition-colors">
            立即开通
          </button>
        </div>
      </aside>
    </div>
  </main>

  <!-- 移动端底部导航栏 -->
  <nav class="fixed bottom-0 left-0 right-0 bg-white border-t border-gray-200 md:hidden z-30">
    <div class="flex items-center justify-around h-16">
      <a href="index.html" class="flex flex-col items-center justify-center text-gray-500">
        <i class="fa fa-home text-xl"></i>
        <span class="text-xs mt-1">首页</span>
      </a>
      <a href="#" class="flex flex-col items-center justify-center text-gray-500">
        <i class="fa fa-compass text-xl"></i>
        <span class="text-xs mt-1">发现</span>
      </a>
      <a href="new-post.html" class="flex flex-col items-center justify-center">
        <div class="w-12 h-12 bg-primary rounded-full flex items-center justify-center -mt-4 shadow-lg">
          <i class="fa fa-plus text-white text-xl"></i>
        </div>
      </a>
      <a href="favorites.html" class="flex flex-col items-center justify-center text-gray-500">
        <i class="fa fa-star-o text-xl"></i>
        <span class="text-xs mt-1">收藏</span>
      </a>
      <a href="profile.html" class="flex flex-col items-center justify-center text-gray-500">
        <i class="fa fa-user-o text-xl"></i>
        <span class="text-xs mt-1">我的</span>
      </a>
    </div>
  </nav>

  <!-- 成功提示弹窗 (默认隐藏) -->
  <div id="success-modal" class="fixed inset-0 bg-black/50 flex items-center justify-center z-50 hidden">
    <div class="bg-white rounded-xl p-6 max-w-sm w-full mx-4 text-center">
      <div class="w-16 h-16 bg-green-100 rounded-full flex items-center justify-center mx-auto mb-4">
        <i class="fa fa-check text-2xl text-green-500"></i>
      </div>
      <h3 class="text-lg font-bold text-gray-900 mb-2">发布成功</h3>
      <p class="text-gray-600 mb-6">你的帖子已成功发布，现在可以在首页查看</p>
      <div class="flex space-x-3">
        <button id="view-post-btn" class="flex-1 px-4 py-2 bg-primary text-white rounded-lg hover:bg-primary/90 transition-colors">
          查看帖子
        </button>
        <button id="back-home-btn" class="flex-1 px-4 py-2 border border-gray-200 text-gray-700 rounded-lg hover:bg-gray-50 transition-colors">
          返回首页
        </button>
      </div>
    </div>
  </div>

  <!-- JavaScript -->
  <script>
    // 标题字数统计
    const titleInput = document.querySelector('input[placeholder="请输入帖子标题..."]');
    const charCount = document.querySelector('.text-right.text-xs.text-gray-500');
    
    if (titleInput && charCount) {
      titleInput.addEventListener('input', function() {
        charCount.textContent = `${this.value.length}/100`;
        
        // 超出字数限制时显示警告颜色
        if (this.value.length > 100) {
          charCount.classList.add('text-red-500');
        } else {
          charCount.classList.remove('text-red-500');
        }
      });
    }
    
    // 标签管理
    const tagInput = document.getElementById('tag-input');
    const addTagBtn = document.getElementById('add-tag-btn');
    const tagContainer = document.getElementById('tag-container');
    let tags = [];
    
    function addTag(tagText) {
      if (!tagText || tags.length >= 5 || tags.includes(tagText)) return;
      
      tags.push(tagText);
      
      const tagElement = document.createElement('div');
      tagElement.className = 'inline-flex items-center bg-primary/10 text-primary text-sm px-3 py-1 rounded-full';
      tagElement.innerHTML = `
        <span>${tagText}</span>
        <button class="ml-1 text-primary hover:text-primary/70" data-tag="${tagText}">
          <i class="fa fa-times-circle"></i>
        </button>
      `;
      
      tagContainer.appendChild(tagElement);
      tagInput.value = '';
      
      // 添加删除标签的事件监听
      tagElement.querySelector('button').addEventListener('click', function() {
        const tagToRemove = this.getAttribute('data-tag');
        tags = tags.filter(tag => tag !== tagToRemove);
        tagElement.remove();
      });
    }
    
    if (tagInput && addTagBtn) {
      // 点击添加按钮添加标签
      addTagBtn.addEventListener('click', function() {
        const tagText = tagInput.value.trim();
        addTag(tagText);
      });
      
      // 按回车键添加标签
      tagInput.addEventListener('keypress', function(e) {
        if (e.key === 'Enter') {
          e.preventDefault();
          const tagText = this.value.trim();
          addTag(tagText);
        }
      });
      
      // 支持空格分隔添加多个标签
      tagInput.addEventListener('keydown', function(e) {
        if (e.key === ' ') {
          e.preventDefault();
          const tagText = this.value.trim();
          if (tagText) {
            addTag(tagText);
          }
        }
      });
    }
    
    // 热门标签点击添加
    const hotTags = document.querySelectorAll('.bg-white.rounded-xl.shadow-sm.p-5.mb-6 button');
    hotTags.forEach(tag => {
      tag.addEventListener('click', function() {
        const tagText = this.textContent.trim();
        addTag(tagText);
      });
    });
    
    // 图片上传预览
    const imageInput = document.querySelector('input[type="file"].hidden');
    const imagePreviewContainer = document.getElementById('image-preview-container');
    
    if (imageInput && imagePreviewContainer) {
      imageInput.addEventListener('change', function() {
        if (this.files && this.files[0]) {
          const reader = new FileReader();
          
          reader.onload = function(e) {
            const imagePreview = document.createElement('div');
            imagePreview.className = 'relative group';
            imagePreview.innerHTML = `
              <img src="${e.target.result}" alt="预览图片" class="w-full h-24 object-cover rounded-lg">
              <button class="absolute top-1 right-1 w-6 h-6 bg-black/50 text-white rounded-full flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity">
                <i class="fa fa-times text-xs"></i>
              </button>
            `;
            
            imagePreviewContainer.appendChild(imagePreview);
            
            // 添加删除图片的事件监听
            imagePreview.querySelector('button').addEventListener('click', function() {
              imagePreview.remove();
            });
          }
          
          reader.readAsDataURL(this.files[0]);
        }
      });
    }
    
    // 开关按钮切换
    const toggleSwitch = document.querySelector('.relative.inline-block.w-10.h-6 input');
    const toggleSpan = document.querySelector('.relative.inline-block.w-10.h-6 span');
    
    if (toggleSwitch && toggleSpan) {
      toggleSwitch.addEventListener('change', function() {
        if (this.checked) {
          toggleSpan.classList.add('bg-primary');
          toggleSpan.classList.remove('bg-gray-200');
          toggleSpan.querySelector('before').classList.add('translate-x-4');
        } else {
          toggleSpan.classList.remove('bg-primary');
          toggleSpan.classList.add('bg-gray-200');
          toggleSpan.querySelector('before').classList.remove('translate-x-4');
        }
      });
    }
    
    // 编辑器工具栏按钮点击效果
    const toolbarButtons = document.querySelectorAll('.editor-toolbar button');
    toolbarButtons.forEach(button => {
      button.addEventListener('click', function() {
        this.classList.toggle('active');
        // 这里可以添加实际的编辑功能
      });
    });
    
    // 发布和保存按钮点击事件
    const publishBtn = document.getElementById('publish-btn');
    const publishBtnMobile = document.getElementById('publish-btn-mobile');
    const saveDraftBtn = document.getElementById('save-draft-btn');
    const successModal = document.getElementById('success-modal');
    const viewPostBtn = document.getElementById('view-post-btn');
    const backHomeBtn = document.getElementById('back-home-btn');
    
    function showSuccessModal() {
      successModal.classList.remove('hidden');
    }
    
    if (publishBtn) {
      publishBtn.addEventListener('click', function() {
        showSuccessModal();
      });
    }
    
    if (publishBtnMobile) {
      publishBtnMobile.addEventListener('click', function() {
        showSuccessModal();
      });
    }
    
    if (saveDraftBtn) {
      saveDraftBtn.addEventListener('click', function() {
        alert('草稿已保存');
      });
    }
    
    if (viewPostBtn) {
      viewPostBtn.addEventListener('click', function() {
        window.location.href = 'post-detail.html';
      });
    }
    
    if (backHomeBtn) {
      backHomeBtn.addEventListener('click', function() {
        window.location.href = 'index.html';
      });
    }
  </script>
</body>
</html>